package com.xinghou.platform.server.api.controller;

import com.google.gson.reflect.TypeToken;
import com.xinghou.platform.entity.req.ShopInfoReq;
import com.xinghou.platform.entity.resp.ShopInfoResp;
import com.xinghou.platform.server.api.bussiness.ShopInfoBusinessService;
import com.xinghou.platform.server.api.bussiness.ShopjobInfoBusinessService;
import com.xinghou.platform.server.api.bussiness.TastInfoBusinessService;
import com.xinghou.platform.util.ConfigUtil;
import com.xinghou.platform.util.JsonUtil;
import com.xinghou.platform.util.StringUtils;
import com.xinghou.platform.util.exception.DBExceptionEnums;
import com.xinghou.platform.util.exception.ServiceException;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

/**
 * 查询门店详细信息
 * @author xuzhen
 *
 */
@Controller
public class GetShopInfoDetailController extends BaseControl {

	private String reqjson;//请求json
	private String repjson;//返回json

	@Resource
	private ShopInfoBusinessService shopInfoBusinessService;
	
	@Resource
	private ShopjobInfoBusinessService shopjobInfoBusinessService;
	
	@Resource
	private TastInfoBusinessService tastInfoBusinessService;
	/*
	private ShopInfoListResp shopInfoListResp;
	private ShopInfoResp shopInfoResp;
	*/
	private String key = ConfigUtil.getProperty("HTTP_SERVICE_KEY");
	
	private boolean bool = false;
	
	/**
	 * 门店详细信息查询
	 * @param shopInfoReq
	 * @param request
	 * @param response
	 * @return
	 * @throws DataAccessException
	 * @throws UnsupportedEncodingException
	 */
	@ResponseBody
	@RequestMapping(value = "/findShopInfo", method = {RequestMethod.POST})
	public String  findShopInfo(
			@RequestBody ShopInfoReq shopInfoReq,
			HttpServletRequest request, HttpServletResponse response) throws DataAccessException, UnsupportedEncodingException{
		ShopInfoResp shopInfoResp = new ShopInfoResp();
		shopInfoResp.setResult("0");
		Map<String,String> requestContent = new HashMap<String, String>();
		requestContent =  (Map<String, String>) JsonUtil.fromJson(reqjson,new TypeToken<Map<String, String>>() {}.getType());
		

			if(StringUtils.isBlank(shopInfoReq.getUserid())){
				throw new ServiceException(DBExceptionEnums.USER_IS_NULL);
			}else if(StringUtils.isBlank(shopInfoReq.getShopid())){
				throw new ServiceException(DBExceptionEnums.SHOPID_IS_NULL);
			}else{
				bool = true;
			}
			
			if(bool){
				shopInfoResp = shopInfoBusinessService.getShopInfoDetail(shopInfoReq.getUserid(), shopInfoReq.getShopid());
				if(shopInfoResp!=null){
					shopInfoResp.setResult("0");
					shopInfoResp.setCkresult("0");
				}else{
					shopInfoResp.setCkresult("1");
				}
					
			}

		repjson = JsonUtil.toJson(shopInfoResp);
		

		return response(shopInfoResp);
	}

	/*public ShopInfoListResp getShopInfoListResp() {
		return shopInfoListResp;
	}

	public void setShopInfoListResp(ShopInfoListResp shopInfoListResp) {
		this.shopInfoListResp = shopInfoListResp;
	}

	public ShopInfoResp getShopInfoResp() {
		return shopInfoResp;
	}

	public void setShopInfoResp(ShopInfoResp shopInfoResp) {
		this.shopInfoResp = shopInfoResp;
	}*/
	
	public String getReqjson() {
		return reqjson;
	}

	public void setReqjson(String reqjson) {
		this.reqjson = reqjson;
	}

	public String getRepjson() {
		return repjson;
	}

	public void setRepjson(String repjson) {
		this.repjson = repjson;
	}

}
